package com.cotte.config;

import java.io.IOException;

import org.apache.hadoop.conf.Configuration;
import org.apache.hadoop.hbase.HBaseConfiguration;
import org.apache.hadoop.hbase.client.Connection;
import org.apache.hadoop.hbase.client.ConnectionFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;


/**
 * 
 * @author LGY
 * Hbase连接池实现
 */
@org.springframework.context.annotation.Configuration
public class HbaseConnectionConfig {
	private  Configuration conf;
	private  Connection hbaseConn;
	@Value("${hbase.zookeeper.quorum}")
	private  String QUORUM;
	@Value("${hbase.zookeeper.port}")
	private  String CLIENT_PORT;
	@Bean
	public  Connection connection(){
		if(hbaseConn == null){
			try {
				conf = HBaseConfiguration.create();
				conf.set("hbase.zookeeper.quorum", QUORUM);
				conf.set("hbase.zookeeper.property.clientPort", CLIENT_PORT);
				conf.set("hbase.master", "kylin-master-0.kylin-master.default.svc.cluster.local:60000");
				hbaseConn = ConnectionFactory.createConnection(conf);
			} catch (IOException e) {
				e.printStackTrace();
			}
		}
		return hbaseConn;
	}
}
